package cn.mythreadtest.test5;

import java.util.Collections;
import java.util.List;

public class MyThread extends Thread{
    List<Integer> list;
    public MyThread(List<Integer> list){
        this.list = list;
    }
    @Override
    public void run() {
        while (true){
            synchronized (MyThread.class){
                if (list.isEmpty()){
                    break;
                }else{
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    System.out.println(getName() + "又产生了一个" + prize + "元大奖");
                }
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
